package com.ysqcould.web.controller.allocation;


import com.ysqcould.allocation.domain.Duty;
import com.ysqcould.allocation.domain.WxRole;
import com.ysqcould.allocation.domain.vo.DutyVo;
import com.ysqcould.allocation.service.IDutyService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 值班Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/allocation/duty")
public class DutyController extends BaseController
{
    @Autowired
    private IDutyService dutyService;

    /**
     * 查询值班列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:duty:list')")
    @GetMapping("/list")
    public TableDataInfo list(Duty duty)
    {
        startPage();
        List<DutyVo> list = dutyService.selectDutyList(duty);
        return getDataTable(list);
    }

    /**
     * 导出值班列表
     */
   /* @PreAuthorize("@ss.hasPermi('allocation:duty:export')")
    @Log(title = "值班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Duty duty)
    {
        List<Duty> list = dutyService.selectDutyList(duty);
        ExcelUtil<Duty> util = new ExcelUtil<Duty>(Duty.class);
        util.exportExcel(response, list, "值班数据");
    }*/

    /**
     * 获取值班详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:duty:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dutyService.selectDutyById(id));
    }

    /**
     * 新增值班
     */
    @PreAuthorize("@ss.hasPermi('allocation:duty:add')")
    @Log(title = "值班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Duty duty)
    {
        duty.setAsId(getUserId());
        return toAjax(dutyService.insertDuty(duty));
    }

    /**
     * 修改值班
     */
    @PreAuthorize("@ss.hasPermi('allocation:duty:edit')")
    @Log(title = "值班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Duty duty)
    {
        return toAjax(dutyService.updateDuty(duty));
    }

    /**
     * 删除值班
     */
    @PreAuthorize("@ss.hasPermi('allocation:duty:remove')")
    @Log(title = "值班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dutyService.deleteDutyByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody Duty duty)
    {
        return toAjax(dutyService.updateStatus(duty));
    }
}
